<?php

/**
* GuideListTest.php
*
* Guid add test
*
* @author     Blazej Zieba <b@zieba.info>
* @copyright  2007 konekto.com
* @version    CVS: $Id:$
*/
require_once '../framework/config.php';

require_once 'simpletest/autorun.php';
require_once 'simpletest/web_tester.php';

require_once '../GuideList.class.php';

class  GuideListTest extends WebTestCase
{
    private $url;
    private $idArray = array();

    public function setUp() 
    {
        $global = &PEAR::getStaticProperty('CONFIG_INI','GLOBAL');
        $this->url = $global['service_url'];
        
        $options = &PEAR::getStaticProperty('CONFIG_INI','DSN');  
  
        $dbh = new PDO($options['dsn_string']);        
        $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

        $dbh->exec("INSERT INTO guide (name) values ( 'UNIT_TEST_GUIDE0' )");
        $this->idArray['UNIT_TEST_GUIDE0'] = $dbh->lastInsertId();
        $dbh->exec("INSERT INTO guide (name) values ( 'UNIT_TEST_GUIDE1' )");
        $this->idArray['UNIT_TEST_GUIDE1'] = $dbh->lastInsertId();
        $dbh->exec("INSERT INTO guide (name) values ( 'UNIT_TEST_GUIDE2' )");
        $this->idArray['UNIT_TEST_GUIDE2'] = $dbh->lastInsertId();

        $this->addHeader("User-Agent: Mozilla/5.0(SymbianOS/9.2; U; Series60/3.1 NokiaE51/1.00.000; Profile/MIDP-2.0 Configuration/CLDC-1.1;)AppleWebKit/413(KHTML,like Gecko)Safari/413");                 
        $this->get($this->url.'?cmd=GuideList');
    }

    public function testGuideList()
    {

        $this->assertTitle('Wirtualny Przewodnik');
        
        $this->assertLink('UNIT_TEST_GUIDE0',$this->url."?cmd=ShowRoute&id=".$this->idArray['UNIT_TEST_GUIDE0']);
        $this->assertLink('UNIT_TEST_GUIDE1',$this->url."?cmd=ShowRoute&id=".$this->idArray['UNIT_TEST_GUIDE1']);
        $this->assertLink('UNIT_TEST_GUIDE2',$this->url."?cmd=ShowRoute&id=".$this->idArray['UNIT_TEST_GUIDE2']);
        
    }

    public function testCSSSelctionWireless()
    {

        $this->addHeader("User-Agent: Mozilla/5.0(SymbianOS/9.2; U; Series60/3.1 NokiaE51/1.00.000; Profile/MIDP-2.0 Configuration/CLDC-1.1;)AppleWebKit/413(KHTML,like Gecko)Safari/413");        
        $this->get($this->url.'?cmd=GuideList');
        $this->assertPattern('/title="wireless"/');

        
    }

    public function testCSSSelctionTouchscreen()
    {

        $this->addHeader("User-Agent: Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3 ");        
        $this->get($this->url.'?cmd=GuideList');
        $this->assertPattern('/title="touchscreen"/');
     
    }
    
    public function testCSSSelctionDesktop()
    {

        $this->addHeader("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 (.NET CLR 3.5.30729)");        
        $this->get($this->url.'?cmd=GuideList');
        $this->assertPattern('/title="desktop"/');
        
    }

    public function tearDown() 
    {
        $options = &PEAR::getStaticProperty('CONFIG_INI','DSN');  
        $upload = &PEAR::getStaticProperty('CONFIG_INI','UPLOAD');
  
        $dbh = new PDO($options['dsn_string']);        
        $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

        
        $dbh->exec("DELETE FROM guide WHERE name LIKE 'UNIT_TEST_GUIDE%'" );
      
        $dbh = null;
    }
    
}
?>
